﻿using Helpers.Common;
using Helpers.Managers;
using Helpers.Serialization;
using System;
using System.Configuration;
using System.Xml;

/// <summary>
/// Configuration structure for the service.
/// </summary>
[Serializable]
public class ServiceConfiguration
{
    #region Properties

    /// <summary>
    /// 
    /// </summary>
    public int RemoteControlServicePort { get; set; }

    #endregion

    /// <summary>
    /// Initializes a new instance of the ServiceConfiguration class.
    /// </summary>
    public ServiceConfiguration()
    {
    }

    #region Overrided Methods

    /// <summary>
    /// Converts the value of the object to its equivalent string representation.
    /// </summary>
    /// <returns>This <typeparamref name="System.String"/></returns>
    public override string ToString()
    {
        return Helper.ObjectToString(this);
    }

    #endregion
}

/// <summary>
/// Handles the access to the ServiceConfiguration config section.
/// </summary>
public class ServiceConfigurationSectionHandler : IConfigurationSectionHandler
{
    /// <summary>
    /// Creates a ServiceConfiguration configuration section handler.
    /// </summary>
    /// <param name="parent">Parent object.</param>
    /// <param name="configContext">Configuration context object.</param>
    /// <param name="section">Section XML node.</param>
    /// <returns>The created section handler object.</returns>
    public object Create(object parent, object configContext, XmlNode section)
    {
        return XmlSerializer.LoadFromXmlString(section.OuterXml, typeof(ServiceConfiguration));
    }
}